package com.school.view;

import java.awt.BorderLayout;
import java.awt.Button;
import java.awt.Dimension;
import java.awt.EventQueue;

import javax.swing.JFrame;
import javax.swing.JMenu;
import javax.swing.JMenuBar;
import javax.swing.JMenuItem;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JSplitPane;
import javax.swing.JTable;
import javax.swing.JTree;

import com.school.controller.ButtonPanel;
import com.school.view.model.StudentTableModel;

/**
 * @author atolev
 * 
 */
public class WindowBuilderTest {

	private JFrame frmSchulapp;

	private JMenuBar menuBar;
	private JMenu mnDatei;
	private JMenuItem mntmSchlieen;

	private JMenu mnBearbeiten;
	private JMenuItem mntmKopieren;
	private JMenuItem mntmAusschneiden;
	private JMenuItem mntmEinfgen;

	private JMenu mnHilfe;
	private JMenuItem mntmber;
	private JPanel panel;
	private JTree tree;
	private JSplitPane splitPane;
	private JTable table;

	private StudentTableModel model;

	/**
	 * Launch the application.
	 */
	public static void main(String[] args) {
		EventQueue.invokeLater(new Runnable() {
			public void run() {
				try {
					WindowBuilderTest window = new WindowBuilderTest();
					window.frmSchulapp.setVisible(true);
				} catch (Exception e) {
					e.printStackTrace();
				}
			}
		});
	}

	/**
	 * Create the application.
	 */
	public WindowBuilderTest() {
		initialize();
	}

	/**
	 * Initialize the contents of the frame.
	 */
	private void initialize() {
		createMainFrame();

		createMenu();

		createFramPanel();

		createOverviewTree();

		createSplitPane();

		createSchuelerTable();

		createRightSide();
	}

	private void createMenu() {
		menuBar = new JMenuBar();
		frmSchulapp.setJMenuBar(menuBar);

		mnDatei = new JMenu("Datei");
		menuBar.add(mnDatei);

		mntmSchlieen = new JMenuItem("Schließen");
		mnDatei.add(mntmSchlieen);

		mnBearbeiten = new JMenu("Bearbeiten");
		menuBar.add(mnBearbeiten);

		mntmKopieren = new JMenuItem("Kopieren");
		mnBearbeiten.add(mntmKopieren);

		mntmAusschneiden = new JMenuItem("Ausschneiden");
		mnBearbeiten.add(mntmAusschneiden);

		mntmEinfgen = new JMenuItem("Einfügen");
		mnBearbeiten.add(mntmEinfgen);

		mnHilfe = new JMenu("Hilfe");
		menuBar.add(mnHilfe);

		mntmber = new JMenuItem("Über...");
		mnHilfe.add(mntmber);
	}

	/**
	 * 
	 */
	private void createMainFrame() {
		frmSchulapp = new JFrame();
		frmSchulapp.setTitle("Schulapp");
		frmSchulapp.setSize(816, 760);
		frmSchulapp.setBounds(100, 100, 450, 300);
		frmSchulapp.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		frmSchulapp.getContentPane().setLayout(new BorderLayout(0, 0));

	}

	private void createSchuelerTable() {
		model = new StudentTableModel();
		table = new JTable(model);
		table.setPreferredScrollableViewportSize(new Dimension(500, 70));
		table.setFillsViewportHeight(true);
		JScrollPane scrollPane = new JScrollPane(table);
		splitPane.setLeftComponent(scrollPane);
		splitPane.setResizeWeight(0.5);
	}

	private void createRightSide() {
		Button button = new Button("Test");
		button.addActionListener(new ButtonPanel(model));
		splitPane.setRightComponent(button);
	}

	private void createSplitPane() {
		splitPane = new JSplitPane();
		splitPane.setOneTouchExpandable(true);
		panel.add(splitPane, BorderLayout.CENTER);
	}

	private void createOverviewTree() {
		tree = new JTree();
		panel.add(tree, BorderLayout.WEST);
	}

	private void createFramPanel() {
		panel = new JPanel();
		frmSchulapp.getContentPane().add(panel, BorderLayout.CENTER);
		panel.setLayout(new BorderLayout(0, 0));
	}
}
